<?php
declare (strict_types = 1);

namespace app\adminapi\model\organize;

use adminmatrix\admin\model\BaseModel;
use app\adminapi\model\Admin\Admin;
use think\Model;
use think\model\relation\HasMany;
/**
 * @mixin \think\Model
 */
class AdminOrganization extends BaseModel
{


    #------------------------------------------------------------
    #
    #   模型事件
    #
    #------------------------------------------------------------

    # 删除后事件
    public static function onAfterDelete(Model $model)
    {
        # 删除部门
        $model->department()->delete();
    }

    #------------------------------------------------------------
    #
    #   关联模型
    #
    #------------------------------------------------------------

    # 关联部门
    public function department() : HasMany
    {
        return $this->hasMany(AdminDepartment::class , 'organization_id');
    }

    #------------------------------------------------------------
    #
    #   模型取值get Attr
    #
    #------------------------------------------------------------

    # 读取creator_id 创建者id

//    public function getCreatorIdAttr($creator_id){
//        if (empty($creator_id)) return '';
//        return [
//            'key'   =>  $creator_id,
//            'value' =>  (new Admin ) -> where('id' , $creator_id)->value('nickname')
//        ];
//    }
}
